<!DOCTYPE html>
<html>
<head>
    <title>领取优惠券</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="__FRONT__/css/lanren.css">
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body style="margin:0;">
<a href="{:url('index/center')}" style="padding:5px;text-align: center;float:left;">返回</a>
<a href="{:url('index/my_coupon')}" style="padding:5px;text-align: center;float:right;">查看我的优惠券</a>

<div class="demo">
    {foreach $list as $v}
    {if condition="isExistCoupon($v['id'])"}
    <div class="stamp stamp01" style="display: block;">
        <div class="par"><p>早起打卡折扣</p><sub class="sign">￥</sub><span>{$v['money']}</span><sub>优惠券</sub>
            <p>剩余{$v['surplus']}张</p></div>
        <div class="copy"></div>
        <i style="
        font-size: 52px;
        color: #f7f1f1;
        text-align:  center;
        font-weight:  bold;
        background-color: rgba(20, 1, 1, 0.5);
        ">已领取</i>
    </div>
    {else/}

    <div class="stamp stamp04">
        <div class="par"><p>早起打卡折扣</p><sub class="sign">￥</sub><span>{$v['money']}</span><sub>优惠券</sub>
            <p>剩余{$v['surplus']}张</p>
        </div>
        <div class="copy">
            <a href="javascript:void(0);" data-id="{$v['id']}">立即领取</a>
        </div>
    </div>
    {/if}
    {/foreach}

</div>
<script>
    $(function () {
        $('.copy a').click(function () {
            var id = $(this).attr('data-id');
            $.post("{:url('index/get_coupon')}", {'id': id}, function (res) {
                console.log(res);
                if (res.code == 1) {
                    alert(res.msg);
                    return false;
                }
                if (res.code == 0) {
                    alert(res.msg);
                    window.location.reload();
                }
            });
        });
    });
</script>

</body>
</html>